const path = require("path");
const chalk = require('chalk');
const fs = require('fs');
const PAGE_DEMO_PATH = './miniapp/pageModel';
const INPUT_PATH = process.argv[process.argv.length - 1];
const OUTPUT_PATH = './miniapp' + INPUT_PATH;
const startTime = Date.now();
fs.mkdir(OUTPUT_PATH, function(err) {
    if (err) {
        console.log(chalk.red(OUTPUT_PATH + '路径已存在，请更换'));
        return;
    };
    console.log(chalk.blue('创建目录' + OUTPUT_PATH));
    fs.readdir(PAGE_DEMO_PATH, function(err1, data) {
        if (err1) {
            console.log(chalk.red(`请确认demo路径 =》 ${PAGE_DEMO_PATH} 路径是否存在`));
            return;
        };
        //data为一个数组
        console.log(chalk.blue('复制文件' + data));
        data.forEach(item => {
            fs.copyFileSync(`${PAGE_DEMO_PATH}/${item}`, `${OUTPUT_PATH}/${item}`);
        });
        const endTime = Date.now();
        console.log(
            chalk.green('复制完成，用时' + (endTime - startTime) / 1000 + 's')
        );
    });
});
